package com.mifengs.mall.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.LinearLayoutHelper;
import com.mifengs.mall.R;
import com.mifengs.mall.entity.GoodsBean;
import com.mifengs.mall.entity.ScareBuyingBean;
import com.mifengs.mall.entity.UpdateData;
import com.mifengs.mall.widget.CircleRecyclerView.CircleRecyclerView;
import com.mifengs.mall.widget.CircleRecyclerView.ScaleXViewMode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lihaoqi on 2017/11/2.
 */

public class HomeLoopAdapter extends  DelegateAdapter.Adapter<RecyclerView.ViewHolder> {



    private Context mContext;

    private List<GoodsBean> beanList = new ArrayList<>();

    public HomeLoopAdapter(Context mContext) {
        this.mContext = mContext;
    }


    public void setBeanList(List<GoodsBean> beanList) {
        this.beanList = beanList;
        notifyDataSetChanged();
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return new LinearLayoutHelper();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new LoopViewHolder(LayoutInflater.from(mContext).inflate(R.layout.fragment_home_loop_goods,parent,false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if(holder instanceof  LoopViewHolder){
            LoopViewHolder viewHolder = (LoopViewHolder) holder;
            LinearLayoutManager linearLayout = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false);
            viewHolder.rvList.setLayoutManager(linearLayout);
            viewHolder.rvList.setViewMode(new ScaleXViewMode());
            viewHolder.rvList.setNeedCenterForce(true);
            viewHolder.rvList.setNeedLoop(true);

            if(beanList.size()!=0){
                LoopGoodsAdapter adapter = new LoopGoodsAdapter(mContext);
                viewHolder.rvList.setAdapter(adapter);
                adapter.setGoodsBeanList(beanList);
            }

        }
    }

    @Override
    public int getItemCount() {
        return 1;
    }

    public class LoopViewHolder extends RecyclerView.ViewHolder{

        private CircleRecyclerView rvList;

        public LoopViewHolder(View itemView) {
            super(itemView);
            rvList = itemView.findViewById(R.id.rv_list);
        }


    }
}
